package tv.scolopender.activity;

import java.util.ArrayList;
import java.util.Timer;

import tv.scolopender.R;
import tv.scolopender.application.ScoloApp;
import tv.scolopender.json.ScoloJSON;
import tv.scolopender.model.Scolo;
import tv.scolopender.service.PollingService;
import tv.scolopender.timertask.SplashTask;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class SplashActivity extends Activity {

	// Timer
	private Timer splashTimer;
	private static final long DELAY = 1000;
	private final boolean scheduled = false;

	private ScoloApp scoloApp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// FullScreen
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

		setContentView(R.layout.activity_welcome);

		scoloApp = (ScoloApp) getApplication();
		Intent service = new Intent(this, PollingService.class);
		startService(service);
		// Timer for SplashScreen
		// Getting Data for next View
		// Checking User
		splashTimer = new Timer();
		splashTimer.schedule(new SplashTask(this), 1000 * 2);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (scheduled)
			splashTimer.cancel();
		splashTimer.purge();
	}

	private class ReadScolos extends AsyncTask<Void, Void, ArrayList<Scolo>> {

		@Override
		protected ArrayList<Scolo> doInBackground(Void... params) {
			return ScoloJSON.selectNewest(0, 5);
		}
	}

}
